package com.hyw.cm.reg.controller;

import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hyw.cm.common.equipment.dto.EquipmentDTO;
import com.hyw.cm.reg.service.IEquipmentService;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;

@Tag(name = "设备操作", description = "设备管理：注册、激活、查询、删除")
@RestController
@RequestMapping("/equipment")
public class EquipmentController {

  @Resource
  private IEquipmentService equipmentService;

  @PostMapping("/register")
  @Operation(summary = "注册设备")
  public EquipmentDTO add(@Parameter(description = "设备详情") @RequestBody @Valid EquipmentDTO equipment) {
    return equipmentService.create(equipment);
  }

  @PostMapping("/activate/{id}")
  @Operation(summary = "激活设备")
  public Boolean activate(@Parameter(description = "设备编号") @PathVariable String id) {
    return equipmentService.activateById(id);
  }

  @PostMapping("/remove/{id}")
  @Operation(summary = "删除设备")
  public Boolean remove(@Parameter(description = "设备编号") @PathVariable String id) {
    equipmentService.remove(id);
    return Boolean.TRUE;
  }

}
